package com.dhwl.hsh.driver.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dhwl.hsh.lib.utils.SystemTool;
import com.dhwl.hsh.lib.view.CircleImageView;
import com.dhwl.hsh.lib.view.PullToZoomScrollViewEx;
import com.dhwl.hsh.driver.R;
import com.dhwl.hsh.driver.ui.activity.FixLoginPwdActivity;
import com.dhwl.hsh.driver.ui.activity.PersonalInfoActivity;
import com.dhwl.hsh.driver.ui.activity.ProtocolListActivity;
import com.dhwl.hsh.driver.ui.activity.WithdrawActivity;
import com.dhwl.hsh.driver.ui.dialog.LogoutDialogFragment;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 设置页面
 *
 * @author hjd008
 * @version [版本号, 2015-1-6]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class PersonalFragment extends BaseFragment implements View.OnClickListener {

    @Bind(R.id.scroll_view)
    PullToZoomScrollViewEx scrollView;

    CircleImageView userIcon;


    TextView userName;


    TextView tvIdentityUser;


    TextView tvIdentitydriver;

    TextView tvDebt;


    TextView tvRate;

    RelativeLayout tvProtocol;
    RelativeLayout tvTel400;

    RelativeLayout tvFixPwd;

    RelativeLayout tvCheckUpdate;

    Button btnLogout;


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_personal;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    protected void initViews(View self, Bundle savedInstanceState) {

        DisplayMetrics localDisplayMetrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
        int mScreenWidth = localDisplayMetrics.widthPixels;
        LinearLayout.LayoutParams localObject =
                new LinearLayout.LayoutParams(mScreenWidth, (int) getResources().getDimension(R.dimen.mymain_top_height));
        scrollView.setHeaderLayoutParams(localObject);


        View headView = LayoutInflater.from(getActivity()).inflate(R.layout.profile_head_view, null, false);
        View zoomView = LayoutInflater.from(getActivity()).inflate(R.layout.profile_zoom_view, null, false);
        View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.profile_content_view, null, false);

        scrollView.setHeaderView(headView);
        scrollView.setZoomView(zoomView);
        scrollView.setScrollContentView(contentView);


        userIcon = ButterKnife.findById(headView, R.id.icon_bank);
        userName = ButterKnife.findById(headView, R.id.tv_user_name);
        tvIdentityUser = ButterKnife.findById(headView, R.id.tv_user_identity);
        tvIdentitydriver = ButterKnife.findById(headView, R.id.tv_driver_identity);

        tvDebt = ButterKnife.findById(contentView, R.id.tv_personal_debt);
        tvRate = ButterKnife.findById(contentView, R.id.tv_personal_rate);
        tvProtocol = ButterKnife.findById(contentView, R.id.layout_personal_protocol);
        tvTel400 = ButterKnife.findById(contentView, R.id.layout_personal_tel_400);
        tvFixPwd = ButterKnife.findById(contentView, R.id.layout_personal_fix_pwd);
        tvCheckUpdate = ButterKnife.findById(contentView, R.id.layout_personal_check_update);
        btnLogout = ButterKnife.findById(contentView, R.id.btn_logout);

        userIcon.setOnClickListener(this);
        userName.setOnClickListener(this);
        tvIdentityUser.setOnClickListener(this);
        tvIdentitydriver.setOnClickListener(this);

        tvDebt.setOnClickListener(this);
        tvRate.setOnClickListener(this);
        tvProtocol.setOnClickListener(this);
        tvTel400.setOnClickListener(this);
        tvFixPwd.setOnClickListener(this);
        tvCheckUpdate.setOnClickListener(this);
        btnLogout.setOnClickListener(this);

    }

    @Override
    protected void initData() {
        userIcon.setImageResource(R.drawable.icon_comment_head_default);
    }


    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.icon_bank:
            case R.id.tv_user_name:
            case R.id.tv_user_identity:

                intent.setClass(getActivity(), PersonalInfoActivity.class);
                startActivity(intent);
                break;
            //本月待付
            case R.id.tv_personal_debt:
                intent.setClass(getActivity(), WithdrawActivity.class);
                startActivity(intent);
                break;
            case R.id.tv_personal_rate:
                break;
            case R.id.layout_personal_protocol:
                intent.setClass(getActivity(), ProtocolListActivity.class);
                startActivity(intent);
                break;
            case R.id.layout_personal_tel_400:
                SystemTool.call(getActivity(), getString(R.string.tel_400));
                break;
            case R.id.layout_personal_fix_pwd:
                intent.setClass(getActivity(), FixLoginPwdActivity.class);
                startActivity(intent);
                break;
            case R.id.layout_personal_check_update:
                break;
            case R.id.btn_logout:
                new LogoutDialogFragment().show(getActivity().getFragmentManager(), "logout_dialog");
                break;
        }

    }
}
